<template>
  <div class="topic">
    <ul class="list">
      <li v-for="(item, index) in topicList" :key="index" @click="topicDetail(item.id)">
        <div class="t-img">
          <img :src="item.scene_pic_url" alt />
        </div>
        <div class="info">
          <p>{{item.title}}</p>
          <p>{{item.subtitle}}</p>
          <p>￥{{item.price_info}}元起</p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { get } from "../../utils/index";
export default {
  data() {
    return {
      page: 1,
      topicList: [],
      total: 0 //总的页数
    };
  },
  //~小程序提供的下拉刷新(但是需要在app.json中配置)
  onPullDownRefresh() {
    this.page = 1;
    this.getListData();
    wx.stopPullDownRefresh();
  },
  //当页面滑到底部的时候会触发这个函数
  onReachBottom() {
    this.page++;
    //不要让数据超出后端所提供的页数
    if (this.page > this.total) {
      return false;
    }
    this.getListData();
  },
  mounted() {
    this.getListData(true);
  },
  methods: {
    async getListData(first) {
      const data = await get("/topic/listAction", {
        page: this.page
      });
      this.total = data.total;
      if (first) {
        this.topicList = data.data;
      } else {
        // this.topicList=this.topicList.concat(data.data)
        //-es6的解构写法
        this.topicList = [...this.topicList, ...data.data];
      }
    },
    topicDetail(id) {
      wx.navigateTo({
        url: "/pages/topicdetail/main?id=" + id
      });
    }
  }
};
</script>

<style lang="less" scoped>
@import url("./style.less");
</style>